package com.xx.xunyou.serviceImpl;

import com.xx.xunyou.dao.item.xiangcunbanshouli.XiangcunbanshouliDAO;
import com.xx.xunyou.dao.item.xiangcunbanshouli.XiangcunbanshoulicontentDAO;
import com.xx.xunyou.dao.item.xiaochenggushiduo.XiaochenggushiduoContentDAO;
import com.xx.xunyou.entity.item.chizhuzaixiang.vo.ChizhuzaixiangVo;
import com.xx.xunyou.entity.item.xiangcunbanshouli.Xiangcunbanshouli;
import com.xx.xunyou.entity.item.xiangcunbanshouli.Xiangcunbanshoulicontent;
import com.xx.xunyou.entity.item.xiangcunbanshouli.vo.XiangcunbanshouliBaseVo;
import com.xx.xunyou.entity.item.xiaochenggushiduo.XiaochenggushiduoContent;
import com.xx.xunyou.service.XiangcunbanshouliService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: xunyou-parent
 * @author: zhl
 * @create: 2019-04-22
 **/
@Service
public class XiangcunbanshouliServiceImpl implements XiangcunbanshouliService {

    @Autowired
    private XiangcunbanshouliDAO xiangcunbanshouliDAO;

    @Autowired
    private XiangcunbanshoulicontentDAO xiangcunbanshoulicontentDAO;

    @Override
    public Integer queryListCountToManager(Map<String, Object> map) {
        return xiangcunbanshouliDAO.queryListCountToManager(map);
    }

    @Override
    public List<Map> queryListToManager(Map<String, Object> map) {
        return xiangcunbanshouliDAO.queryListToManager(map);
    }

    @Override
    @Transactional
    public void insert(Xiangcunbanshouli xiangcunbanshouli, String content) {
        Date date = new Date();
        xiangcunbanshouli.setCreateTime(date);
        xiangcunbanshouliDAO.insertBackId(xiangcunbanshouli);
        //内容
        Xiangcunbanshoulicontent xiangcunbanshoulicontent = new Xiangcunbanshoulicontent();
        xiangcunbanshoulicontent.setXiangcunbanshouliId(xiangcunbanshouli.getXiangcunbanshouliId());
        xiangcunbanshoulicontent.setContent(content);
        xiangcunbanshoulicontent.setCreateTime(date);
        xiangcunbanshoulicontentDAO.insert(xiangcunbanshoulicontent);
    }

    @Override
    public Xiangcunbanshouli queryByIdToManagr(Integer xiangcunbanshouliId) {
        return xiangcunbanshouliDAO.selectByPrimaryKey(xiangcunbanshouliId);
    }

    @Override
    public Xiangcunbanshoulicontent queryContentByIdToManager(Integer xiangcunbanshouliId) {
        return xiangcunbanshoulicontentDAO.selectByPrimaryKey(xiangcunbanshouliId);
    }

    @Override
    @Transactional
    public void update(Xiangcunbanshouli xiangcunbanshouli, String content) {
        xiangcunbanshouliDAO.updateByPrimaryKeySelective(xiangcunbanshouli);
        //内容
        Xiangcunbanshoulicontent xiangcunbanshoulicontent = new Xiangcunbanshoulicontent();
        xiangcunbanshoulicontent.setXiangcunbanshouliId(xiangcunbanshouli.getXiangcunbanshouliId());
        xiangcunbanshoulicontent.setContent(content);
        xiangcunbanshoulicontentDAO.updateByPrimaryKeySelective(xiangcunbanshoulicontent);
    }

    @Override
    @Transactional
    public void delete(Integer xiangcunbanshouliId) {
        xiangcunbanshouliDAO.deleteByPrimaryKey(xiangcunbanshouliId);
        xiangcunbanshoulicontentDAO.deleteByPrimaryKey(xiangcunbanshouliId);
    }

    @Override
    @Transactional
    public void recommend(Integer xiangcunbanshouliId) {
        xiangcunbanshouliDAO.recommend(xiangcunbanshouliId, new Date());
    }

    @Override
    @Transactional
    public void notRecommend(Integer xiangcunbanshouliId) {
        xiangcunbanshouliDAO.notRecommend(xiangcunbanshouliId);
    }

    @Override
    public List<XiangcunbanshouliBaseVo> queryListToAPPIndex(Map<String, Object> map) {
        return xiangcunbanshouliDAO.queryListToAPPIndex(map);
    }
}
